var index=0
var mPic = document.querySelectorAll("#mpic img")
var bPic = document.getElementById("bpic")
var bPic1 = document.getElementById("bpic1")
var mPic1 = document.querySelectorAll("#mpic1 img")
var div = document.querySelectorAll(".tab-pane")
var allLi = document.querySelectorAll(".nav-tabs li")
var allA = document.querySelectorAll(".nav-tabs li a")

var arr = [
    "images/lunbo1.png",
    "images/lunbo2.png",
    "images/lunbo3.jpg"
]
function showAll(){
    var username = document.getElementById("userName")
    var touxiang = document.querySelector(".touxiang")
    if(!(localStorage.getItem("username"))){
      touxiang.src = "images/tou2.jpeg"
      username.innerHTML="未登录"
    }else{
      touxiang.src="images/tou1.jpg"
      username.innerHTML=`${localStorage.getItem("username")}`
    }
    document.getElementById("lunbo").src=arr[index]
    if(index<arr.length-1){
        index++
      }
      else{
        index=0
      }
    var timer = setTimeout("showAll()",1500)
}
mPic.forEach(item=>{
  item.addEventListener("mouseenter",function(){
    bPic.src=item.src
  })
  item.addEventListener("mouseleave",function(){
    bPic.src="images/g1.png"
  })
})
mPic1.forEach(item=>{
  item.addEventListener("mouseenter",function(){
    bPic1.src=item.src
  })
  item.addEventListener("mouseleave",function(){
    bPic1.src="images/mod1.png"
  })
})
allA.forEach((i,index)=>{
  i.addEventListener("click",function(){
    allA.forEach(a=>{
      a.classList.remove("active")
    })
    i.classList.add("active")
      div.forEach(c=>{
        c.style.display="none"
      })
      div.forEach(b=>{
        div[index].style.display="flex"
    })
  })
})
var xiala = document.querySelector(".dropdown-menu")
var btnxiala = document.querySelector(".xiaLa")
btnxiala.addEventListener("click",function(){
  xiala.classList.toggle("jihuo")
})
var geren =  document.querySelector(".div1")
geren.addEventListener("click",function(){
  if(!(localStorage.getItem("username"))){
    alert("请先登录")
    location.href="login.html"
  }else{
    location.href="geren.html"
  }
})
window.onload=showAll